<h1>Table</h1>

<p>The Table action is used to create a table of string literals that can be 
referenced by an index rather than using the literal value when executing a 
sequence of actions.</p>

<p>Variables and built-in functions are specified by their name and the Table 
action contains a table of the respective strings. References to a variable or 
function can then use its index in the table rather than the name resulting in 
a more compact representation when the actions are encoded into binary form.</p>

<table>

<tr>
<th nowrap>Field Name</th>
<th>Type</th>
<th>Size</th>
<th>Description</th>
</tr>

<tr>
<td nowrap valign="top"><a name="ActionType">Type</a></td>
<td nowrap valign="top">unsigned int</td>
<td nowrap valign="top" align="right">8</td>
<td>Identifies the action when it is encoded.</td>
</tr>

<tr>
<td nowrap valign="top"><a name="ActionLength">Length</a></td>
<td nowrap valign="top">unsigned int</td>
<td nowrap valign="top" align="right">16</td>
<td>The number of bytes in the rest of the encoded action. The total number of
bytes in the encoded action is Length+3.</td>
</tr>

<tr>
<td nowrap valign="top"><a name="ActionLength">variableCount</a></td>
<td nowrap valign="top">unsigned int</td>
<td nowrap valign="top" align="right">16</td>
<td>The number of entries in the table.</td>
</tr>

<tr>
<td nowrap valign="top">values</td>
<td nowrap valign="top">String</td>
<td nowrap valign="top" align="right">[variableCount]</td>
<td>An array of up to 65536 strings.</td>
</tr>
</table>

<p>The use of the Table action is illustrated in the following simple expression:</p>

<pre>
var1 = (var1 + var2) / (var1 - var3);
</pre>

<p>This can be translated into the following sequence of actions:</p>

<pre>
FSTable values = new FSTable();

values.add("var1");
values.add("var2");
values.add("var3");

actions.add(values);

actions.add(new FSPush(FSTableIndex(0)));            // var1
actions.add(FSAction.GetVariable());
actions.add(new FSPush(FSTableIndex(0)));            // var1
actions.add(FSAction.GetVariable());
actions.add(new FSPush(FSTableIndex(1)));            // var2
actions.add(FSAction.GetVariable());
actions.add(new FSAction(FSAction.Add));
actions.add(new FSPush(FSTableIndex(0)));            // var1
actions.add(FSAction.GetVariable());
actions.add(new FSPush(FSTableIndex(2)));            // var3
actions.add(FSAction.Subtract());
actions.add(FSAction.Divide());
actions.add(FSAction.SetVariable());
</pre>

<p>The table in the Table action can support up to 65536 different variables. As 
a result using the FSVariable class to reference the variables in the example 
above uses one byte rather than the five required to represent the name directly 
(including the null character terminating the string).</p>

<p>The FSTable stores the strings in an array. No checking for duplicate values is performed.</p>

<h2>History</h2>

<p>The Table action represents the ActionConstantPool in the Macromedia Flash (SWF)
File Format Specification. It was introduced in Flash 5. It was extended in Flash 
6 to support tables of up to 65536 strings.</p>
